<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" href="docgen-resources/docgen.css" type="text/css">
  <meta name="generator" content="FreeMarker Docgen (DocBook 5)">
  <title>
    FreeMarker Manual - Create a data-model
  </title>
    <script type="text/javascript" src="docgen-resources/jquery.js"></script>
    <script type="text/javascript" src="docgen-resources/linktargetmarker.js"></script>
</head>
<body>

    <div class="navigation">
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="pgui.html">Programmer's Guide</a>
            <b>></b>
          <a href="pgui_quickstart.html">Getting Started</a>
            <b>></b>
          Create a data-model
</span>    </div>
    <div class="bookmarks">
<span class="bookmarks">Bookmarks:
<a href="alphaidx.html">Alpha. index</a>, <a href="gloss.html">Glossary</a>, <a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a>, <a href="ref_builtins_alphaidx.html">?builtins</a>, <a href="ref_directive_alphaidx.html">#directives</a>, <a href="ref_specvar.html">.spec_vars</a>, <a href="app_faq.html">FAQ</a>, <a href="api/index.html">API</a>, <a href="../index.html">Home</a></span>    </div>
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="pgui_quickstart_gettemplate.html"><span class="hideA">Next page: </span>Get the template</a></div><div class="pagerButton"><a href="pgui_quickstart_createconfiguration.html">Previous page</a></div><div class="pagerButton"><a href="pgui_quickstart.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    </div>

<div id="mainContent">

  
  
  
  
  <h1 class="rank_section1"
        id="pageTopTitle">
<a name="pgui_quickstart_createdatamodel"></a>Create a data-model  </h1>
    
    
<p>In simple cases you can build data-models using
        <tt style="color: #A03D10">java.lang</tt> and <tt style="color: #A03D10">java.util</tt> classes
        and custom Java Beans:</p>    <div class="itemizedlist">
<ul>
          <li>
            <p>Use <tt style="color: #A03D10">java.lang.String</tt> for strings.</p>
          </li>

          <li>
            <p>Use <tt style="color: #A03D10">java.lang.Number</tt> descents for
            numbers.</p>
          </li>

          <li>
            <p>Use <tt style="color: #A03D10">java.lang.Boolean</tt> for boolean
            values.</p>
          </li>

          <li>
            <p>Use <tt style="color: #A03D10">java.util.List</tt> or Java arrays for
            sequences.</p>
          </li>

          <li>
            <p>Use <tt style="color: #A03D10">java.util.Map</tt> for hashes.</p>
          </li>

          <li>
            <p>Use your custom bean class for hashes where the items
            correspond to the bean properties. For example the
            <tt style="color: #A03D10">price</tt> property
            (<tt style="color: #A03D10">getProperty()</tt>) of <tt style="color: #A03D10">product</tt>
            can be get as <tt style="color: #A03D10">product.price</tt>. (The actions of
            the beans can be exposed as well; see much later <a href="pgui_misc_beanwrapper.html">here</a>)</p>
          </li>
        </ul>    </div>
<p>For example, let's build the data-model of the <a href="dgui_quickstart_basics.html#example.first">first example of the Template Author's
        Guide</a>. For convenience, here it is again:</p><div align="left" class="programlisting"><table bgcolor="#99CCFF" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#99CCFF" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
(root)
  |
  +- user = &quot;Big Joe&quot;
  |
  +- latestProduct
      |
      +- url = &quot;products/greenmouse.html&quot;
      |
      +- name = &quot;green mouse&quot;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>
<p>This is the Java code fragment that builds this
        data-model:</p><div align="left" class="programlisting"><table bgcolor="#F8F8F8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#F8F8F8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
// Create the root hash
Map root = new HashMap();
// Put string ``user'' into the root
root.put(&quot;user&quot;, &quot;Big Joe&quot;);
// Create the hash for ``latestProduct''
Map latest = new HashMap();
// and put it into the root
root.put(&quot;latestProduct&quot;, latest);
// put ``url'' and ``name'' into latest
latest.put(&quot;url&quot;, &quot;products/greenmouse.html&quot;);
latest.put(&quot;name&quot;, &quot;green mouse&quot;);&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>
<p>For the <tt style="color: #A03D10">latestProduct</tt> you might as well use a
        Java Bean that has <tt style="color: #A03D10">url</tt> and <tt style="color: #A03D10">name</tt>
        properties (that is, an object that has public <tt style="color: #A03D10">String
        getURL()</tt> and <tt style="color: #A03D10">String getName()</tt> methods);
        it's the same from viewpoint of the template. Similarly, the root
        could be a Java Bean with <tt style="color: #A03D10">user</tt> and
        <tt style="color: #A03D10">lastestProduct</tt> properties.</p>  
</div>

    <div class="navigation">
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="pgui_quickstart_gettemplate.html"><span class="hideA">Next page: </span>Get the template</a></div><div class="pagerButton"><a href="pgui_quickstart_createconfiguration.html">Previous page</a></div><div class="pagerButton"><a href="pgui_quickstart.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="pgui.html">Programmer's Guide</a>
            <b>></b>
          <a href="pgui_quickstart.html">Getting Started</a>
            <b>></b>
          Create a data-model
</span>    </div>
    </div>

<table border=0 cellspacing=0 cellpadding=0 width="100%">
    <tr>
      <td colspan=2><img src="docgen-resources/img/none.gif" width=1 height=8 alt=""></td>
    <tr>
      <td align="left" valign="top"><span class="smallFooter">
            FreeMarker Manual -- For FreeMarker 2.3.20
            <br>
          HTML generated: 2013-06-27 20:54:33 GMT
      </span></td>
      <td align="right" valign="top"><span class="smallFooter">
          <a href="http://www.xmlmind.com/xmleditor/">
            <img src="docgen-resources/img/xxe.gif" alt="Edited with XMLMind XML Editor">
          </a>
      </span></td>
    </tr>
</table>
  <!-- Put pre-loaded images here: -->
  <div style="display: none">
    <img src="docgen-resources/img/linktargetmarker.gif" alt="Here!" />
  </div>
</body>
</html>

